package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NusingProjectController
 * @Author LiShunSen
 * @Date 2024-08-24
 */
@Slf4j
@RestController
@Api(tags = "护理项目相关接口")
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nusingProjectService;


    /**
     * 分页查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询")

    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态:0-禁用,1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {

        PageResponse<NursingProjectVo> pageResponse = nusingProjectService.getByPage(name, pageNum, pageSize, status);

        return success(pageResponse);
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult addProjec(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDto) {

        nusingProjectService.addProjec(nursingProjectDto);

        return success();
    }

    /**
     * 根据id查询护理
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingProjectVo> getById(@PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVo = nusingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("编辑项目")
    public ResponseResult updateProject(@RequestBody NursingProjectDto nursingProjectDto) {

        nusingProjectService.updateProject(nursingProjectDto);

        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult statusProject(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        nusingProjectService.statusProject(id, status);

        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除项目")
    public ResponseResult deletProJect(
            @ApiParam(value = "护理项目ID", required = true)
            @PathVariable("id") Long id) {
        nusingProjectService.deletProJect(id);
        return success();
    }

    @GetMapping("all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> findAll() {
        List<NursingProjectVo> nursingProjectVo = nusingProjectService.findAll();
        return success(nursingProjectVo);
    }
}
